import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;

public class demo4 {
    public static void main(String[] args) throws ParserConfigurationException, IOException, SAXException {
        DocumentBuilderFactory dbf=DocumentBuilderFactory.newDefaultInstance();
        DocumentBuilder db=dbf.newDocumentBuilder();
        Document doc=db.parse("src/demo.xml");
        NodeList list=doc.getElementsByTagName("Brand");
        for (int i=0;i<list.getLength();i++){
            Element brandElement= (Element) list.item(i);
            String brandName=brandElement.getAttribute("name");
            if (brandName.equals("SAMSUNG")){
                brandElement.getParentNode().removeChild(brandElement);
            }
        }
    }
}
